<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" PLACEHOLDER="请输入一个1-100的数字:">
<input type="button" value="猜一猜" onclick="guess()">
<div></div>


<script>
  var num = parseInt(Math.random()*100+1);
  var l = document.querySelector("input[type='text']");
  var d = document.querySelector("div");

  var count = 0;
  function guess(){
    if (isNaN(l.value)){
      d.innerText = "请输入一个1-100的数字:";
    }
    count+=1;

    if (l.value>num){
      d.innerText = "你猜大了=-=";
    }else if(l.value<num){
      d.innerText = "你猜小了=-=";
    }else {
      d.innerText = "恭喜你,猜对了!总共猜了"+count+"次!你可以继续猜下一个数字哦";
      num = parseInt(Math.random()*100+1);
      count = 0;
    }
    l.value="";
    console.log(num)
  }



</script>



</body>
</html>